package rsj.service.report;

import com.alibaba.fastjson.JSON;
import com.rlyy.aibase.utils.base.TableNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import rsj.api.report.entity.ProductCategoryReport;
import rsj.api.report.entity.ProductCategoryReportDetail;
import rsj.api.report.entity.ReportParam;
import rsj.sql.product.ProductCategoryReportDao;

import java.util.List;

/**
 * 接口分类报表
 *
 * @author yuanqinglong
 * @since 2021/7/22 9:12
 */
@Service
public class ProductCategoryReportServiceImpl implements IReportService<ProductCategoryReport, ProductCategoryReportDetail, ReportParam> {



    @Autowired
    private ProductCategoryReportDao productCategoryReportDao;


    /**
     * 报告列表
     *
     * @param reportParam 报告参数
     * @return {@link List<ProductCategoryReport>}
     */
    @Override
    public List<ProductCategoryReport> reportList(ReportParam reportParam) {
        TableNode tableNode = productCategoryReportDao.productCategoryReportList(reportParam);
        List<ProductCategoryReport> productCategoryReports = JSON.parseArray(tableNode.toJson(), ProductCategoryReport.class);
        productCategoryReports.forEach(productCategoryReport -> productCategoryReport.processingAttributeValue(reportParam));
        return productCategoryReports;
    }

    /**
     * 报告数
     *
     * @param reportParam 报告参数
     * @return int
     */
    @Override
    public int reportCount(ReportParam reportParam) {
        return productCategoryReportDao.productCategoryReportCount(reportParam).valueInt();
    }


    /**
     * 详细的列表
     *
     * @param reportParam 报告参数
     * @return {@link List<ProductCategoryReportDetail>}
     */
    @Override
    public List<ProductCategoryReportDetail> detailList(ReportParam reportParam) {
        TableNode tableNode = productCategoryReportDao.productCategoryReportDetailList(reportParam);
        List<ProductCategoryReportDetail> productCategoryReportDetails = JSON.parseArray(tableNode.toJson(), ProductCategoryReportDetail.class);
        productCategoryReportDetails.forEach(ProductCategoryReportDetail::calculateRate);
        return productCategoryReportDetails;
    }


    /**
     * 详细的计算
     *
     * @param reportParam 报告参数
     * @return int
     */
    @Override
    public int detailCount(ReportParam reportParam) {
        return productCategoryReportDao.productCategoryReportDetailCount(reportParam).valueInt();
    }




}
